package com.springboot.study.controller;

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.springboot.study.entity.User;
import com.springboot.study.mapper.UserMapper;
import com.springboot.study.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class HelloWordController {
    @GetMapping
    public String getHelloWord() {
        return "Hello World!";
    }

    @GetMapping("/{id}")
    public String getHelloWord(@PathVariable Long id) {
        return "Hello World!" + id;
    }

    @PostMapping("/post")
    public String postHelloWord(@RequestBody Map<String,String> map) {
        System.out.printf(map.toString());
        return "POST Hello World!";
    }

    @PutMapping("/put/{id}")
    public String putHelloWord(@PathVariable Long id,@RequestBody Map<String,String> map) {
        System.out.printf("%s\n", id);
        System.out.printf(map.toString());
        return "PUT Hello World!";
    }

    @DeleteMapping("/delete/{id}")
    public String deleteHelloWord(@PathVariable Long id,@RequestBody Map<String,String> map) {
        System.out.printf("%s\n", id);
        System.out.printf(map.toString());
        return "DELETE Hello World!";
    }

    @Resource
    private UserMapper userMapper;

    @GetMapping("/test")
    public void testSelect() {
        System.out.println(("----- selectAll method test ------"));
        List<User> userList = userMapper.selectList(null);
        Assert.isTrue(5 == userList.size(), "");
        userList.forEach(System.out::println);
    }

    @Resource
    private UserService userService;

    @GetMapping("/test2")
    public void testSelect2() {
        List<User> userList = userService.list();
        userList.forEach(System.out::println);
    }

}
